package ru.lenwp.operation.client;

import ru.lenwp.context.Context;
import ru.lenwp.model.Account;
import ru.lenwp.model.Client;
import ru.lenwp.model.OperationInfo;
import ru.lenwp.model.User;
import ru.lenwp.operation.Operation;
import ru.lenwp.util.ConsoleUtil;
import ru.lenwp.util.GenerationNumber;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Lenar on 10.08.2014.
 */
public class CreateAccountOperation implements Operation {
    private final Context context;


    public CreateAccountOperation(Context context) {
        this.context = context;
    }

    public void createAccount(Context context) {
        Account account = new Account();
        User user = context.getCurrentUser();
            if (user instanceof Client) {
                double sum = ConsoleUtil.askDouble("Введите сумму: ");
                String number = String.valueOf(context.nextAccountId());
                account.setClient((Client) user);
                account.setNumber(number);
                account.setSum(sum);
                context.getAccountDao().insert(account);
            }
    }


    @Override
    public OperationInfo execute() {
        createAccount(context);
        return null;
    }

    @Override
    public String getOperationName() {
        return "Создание нового счета.";
    }
}
